class CategorySubscription < ActiveRecord::Base
  belongs_to :user
  belongs_to :category

  def self.create_subscription(category_id, user_id, keywords)
    CategorySubscription.delete_all(:category_id => category_id, :user_id => user_id)
    cs = CategorySubscription.new(:category_id => category_id, :user_id => user_id, :keywords => keywords)
    cs.save
    return cs
  end

  def self.delete_subscription(category_id, user_id)
    CategorySubscription.delete_all(:category_id => category_id, :user_id => user_id)
  end

  def self.is_subscriber(category_id, user_id)
    return (self.find_by_category_id_and_user_id(category_id,user_id) != nil)
  end
end
